home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / SLTPU70C / SAMPLE6.PAS < prev    next >
Pascal/Delphi Source File  |  1993-09-16  |  4KB  |  100 lines

  1.  
  2. Program Sample6;
  3.  
  4.   { Sample program to list a file directory, including long descriptions }
  5.  
  6. Uses Filedef,Dir,Sublist,General,Message;
  7.  
  8. var dirname: string;
  9.     longdescrip: msgptr;
  10.     filerec: dirtype;
  11.     i: integer;
  12.  
  13.  
  14.   Procedure ProcessFile (n: longint);    { recursive processing routine }
  15.   Begin
  16.     ReadDir(filerec,n);
  17.     if filerec.leaf.left<>0 then begin
  18.       ProcessFile(filerec.leaf.left);   { Do the left branch }
  19.       ReadDir(filerec,n);               { Get the original record back }
  20.     end;
  21.  
  22.     with filerec do begin  { here is where we display each filename }
  23.       writeln(name,' : ',descrip);   { name and short description }
  24.  
  25.       if EdfTxt<>0 then begin            { File has an extended description }
  26.         GetDescription(EdfTxt,LongDescrip);
  27.         if (LongDescrip<>Nil) then begin      { See Note (1) Below }
  28.           for i:=1 to LongDescrip^.MsgLen do
  29.             writeln(' ',LongDescrip^.MsgLin[i]^);
  30.           DisposeMsg(Longdescrip);
  31.         end;
  32.       end else begin               { Check for old style description }
  33.         for i:=1 to 2 do           { See Note (2) Below }
  34.           if Edescrip[i]<>'' then writeln(Edescrip[i]);
  35.       end;
  36.       writeln;
  37.     end;
  38.  
  39.     if filerec.leaf.right<>0
  40.       then ProcessFile(filerec.leaf.right);    { Do the right branch }
  41.   end;
  42.  
  43.  
  44.  
  45.  
  46. Begin
  47.  
  48.   { Open CONFIG and NODES files }
  49.   if OpenFiles([CONFIGF,NODESF]) then begin
  50.  
  51.     { Initialize list of filedirs }
  52.     SubLIstInit(Filedirs);
  53.  
  54.     { get name of directory to process }
  55.     writeln;
  56.     writeln('Enter name of directory to list:');
  57.     readln(dirname);
  58.     writeln;
  59.  
  60.     Upstr(dirname);         { convert to all uppercase }
  61.     StripSpaces(dirname);   { remove leading & trailing spaces }
  62.  
  63.     if OpenDir(dirname,MainDir) then begin
  64.       ProcessFile(DirFileRoot);   { Start processing from root }
  65.       CloseDir(MainDir);
  66.     end else begin
  67.       writeln('Error: could not open directory ',dirname);
  68.     end;
  69.  
  70.     CloseAllFiles;
  71.   end
  72.   else writeln('Could not open CONFIG File!');
  73.  
  74. end.
  75.  
  76.  
  77. { Notes:
  78.   (1) After calling GetDescription, check to see if result is Nil; if
  79.       so, do not process description. The result might be Nil in the
  80.       case where the EdfTxt pointer is garbage, or points to text that
  81.       is no longer available (some records may contain garbage as a
  82.       result of having been added by software which did not clear the
  83.       unused space in the record to zeros before adding the record).
  84.       Be sure to fill "Unused" areas of all Searchlight data structures
  85.       with binary zeros before saving them, so that future programs that
  86.       use the areas will know when there is valid data present.
  87.  
  88.   (2) Notice that we look at the Edescrip fields only if we did not find
  89.       a pointer in EdfTxt. This assumes that any program which stores an
  90.       extended description via the new functions will not store anything
  91.       here; this should be considered standard practice. In other words,
  92.       a file will have either an old 2 line description or a new extended
  93.       description, but not both. If you wish to expand the description of
  94.       an existing file, you should copy any text out of the Edescrip fields
  95.       into a MsgPtr variable and save it as an extended description. Note
  96.       that we might also check the Edescrip fields if the result of
  97.       GetDescription was Nil (assuming that the EdfTxt pointer contained
  98.       random garbage and the record probably was not intentionally saved
  99.       with an extended description).
  100. }